home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / misc / robots.lha / player / anticlock.r next >
Text File  |  1993-04-25  |  2KB  |  72 lines

  1. Me myself and I
  2. laza
  3. /* clockwork.r /*
  4. /* main */
  5. main()
  6. {
  7.    int   range, sangl, angl, nx, nz, radius;
  8.  
  9.    angl = plot_course(500, 500) + 180; 
  10.    rot = angl + 10;
  11.    sangl = rand(360);
  12.    while(1)
  13.    {
  14.       if (rot >= 360)
  15.          rot -= 360;
  16.       radius = 300;
  17.       nx = 500 + (radius * cos(rot)) / 100000;
  18.       ny = 500 + (radius * sin(rot)) / 100000;
  19.       angl = plot_course(nx, ny);
  20.       drive(angl, 49);
  21.       while((loc_x() - nx > 3) || (nx - loc_x() > 3))
  22.       {
  23.          range = scan(sangl, 10);
  24.          if (range != 0 && range < 700)
  25.          {
  26.             cannon(sangl, range);
  27.             sangl -= 20;
  28.          }
  29.          sangl += 10;
  30.       }
  31.       rot += 20;
  32.    }
  33. }
  34.  
  35. plot_course(xx,yy)
  36. int xx, yy;
  37. {
  38.   int d;
  39.   int x,y;
  40.   int scale;
  41.   int curx, cury;
  42.  
  43.   scale = 100000;  /* scale for trig functions */
  44.   curx = loc_x();  /* get current location */
  45.   cury = loc_y();
  46.   x = curx - xx;
  47.   y = cury - yy;
  48.  
  49.   /* atan only returns -90 to +90, so figure out how to use */
  50.   /* the atan() value */
  51.  
  52.   if (x == 0) {      /* x is zero, we either move due north or south */
  53.     if (yy > cury)
  54.       d = 90;        /* north */
  55.     else
  56.       d = 270;       /* south */
  57.   } else {
  58.     if (yy < cury) {
  59.       if (xx > curx)
  60.         d = 360 + atan((scale * y) / x);  /* south-east, quadrant 4 */
  61.       else
  62.         d = 180 + atan((scale * y) / x);  /* south-west, quadrant 3 */
  63.     } else {
  64.       if (xx > curx)
  65.         d = atan((scale * y) / x);        /* north-east, quadrant 1 */
  66.       else
  67.         d = 180 + atan((scale * y) / x);  /* north-west, quadrant 2 */
  68.     }
  69.   }
  70.   return(d);
  71. }
  72.